﻿using System;
using System.Collections.Generic;
using System.Text;
using PlugNT.Custom;
using PlugNT.Cms.Model;
using System.Data;
using PlugNT.Safe;

namespace PlugNT.Cms.BLL
{
    public class Advertise
    {
        private static readonly PlugNT.Cms.DAL.Advertise dal = new PlugNT.Cms.DAL.Advertise();

        private string _currPostfix = WebConfig.TablePostfix;




        public string CurPostfix
        {
            get { return _currPostfix; }
            set { _currPostfix = value; }
        }






        public AdvertiseInfo GetAdvertiseInfo(int id)
        {
            return dal.GetAdvertiseInfo(id, _currPostfix);
        }








        public bool Add(AdvertiseInfo model)
        {
            return dal.Add(model, _currPostfix);
        }


        public bool UpdateClickCount(AdvertiseInfo model)
        {
            return dal.UpdateClickCount(model, _currPostfix);
        }


        public bool AddClickCount(int articleId)
        {
            return dal.AddClickCount(articleId, _currPostfix);
        }


        public bool Update(AdvertiseInfo model)
        {
            return dal.Update(model);
        }




        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Delete(int id)
        {
            return dal.Delete(id, _currPostfix);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="andWhere"></param>
        /// <param name="orderBy"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public DataTable GetIdList(int topcount, string andWhere, string orderBy, string desc)
        {
            if (orderBy != null && andWhere != null)
            {
                if (desc != null)
                {
                    andWhere = andWhere + " order by " + orderBy + " " + desc;
                }
                else
                {
                    andWhere = andWhere + " order by " + orderBy;
                }

                return dal.GetList(topcount, " and " + andWhere, "");
            }
            return dal.GetList(topcount, "", "");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currPage"></param>
        /// <param name="isexact"></param>
        /// <param name="locked"></param>
        /// <param name="showSql"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetList(int pageSize, int currPage, bool isexact, bool showSql, out int recordCount)
        {
            StringBuilder andWhere = new StringBuilder();


            recordCount = dal.GetCount(andWhere.ToString(), _currPostfix);
            return dal.GetList(pageSize, currPage, andWhere.ToString(), showSql, _currPostfix);
        }
        public DataTable GetIdList(string andWhere, string currPostfix)
        {
            return dal.GetIdList(andWhere, currPostfix);
        }
        public DataTable GetIdList(string currPostfix)
        {
            return dal.GetIdList("", currPostfix);
        }

    }
}
